package com.prs.crm.service.sale.impl;

import java.io.Serializable;

import com.prs.crm.context.Constrains;
import com.prs.crm.dao.sale.SalesReceivesRegistBillRealityDao;
import com.prs.crm.domain.fs.Detail;
import com.prs.crm.domain.sale.SalesReceivesRegistBillReality;
import com.prs.crm.service.fs.DetailService;
import com.prs.crm.service.impl.BaseServiceImpl;
import com.prs.crm.service.sale.SalesReceivesRegistBillRealityService;

public class SalesReceivesRegistBillRealityServiceImpl
		extends
		BaseServiceImpl<SalesReceivesRegistBillReality, SalesReceivesRegistBillRealityDao>
		implements SalesReceivesRegistBillRealityService {

	private SalesReceivesRegistBillRealityService salesReceivesRegistBillRealityService;

	private DetailService detailService;

	@Override
	public void saveOrfund(
			SalesReceivesRegistBillReality salesReceivesRegistBillReality) {
		this.getSalesReceivesRegistBillRealityService().save(
				salesReceivesRegistBillReality);

		Double sum = this.getDetailService().getBalanceByAccount(
				salesReceivesRegistBillReality.getBankAccount());
		Detail detial = new Detail();
		detial
				.setSalesReceivesRegistBillReality(salesReceivesRegistBillReality);
		detial.setIncome(salesReceivesRegistBillReality.getBillAmount());
		detial.setPay(0.00);
		detial.setBalance(salesReceivesRegistBillReality.getBillAmount() + sum);
		detial.setBankAccount(salesReceivesRegistBillReality.getBankAccount());
		detial.setItem(Constrains.FS_ITEMS_SALES);

		this.getDetailService().save(detial);

	}

	public SalesReceivesRegistBillRealityService getSalesReceivesRegistBillRealityService() {
		return salesReceivesRegistBillRealityService;
	}

	public void setSalesReceivesRegistBillRealityService(
			SalesReceivesRegistBillRealityService salesReceivesRegistBillRealityService) {
		this.salesReceivesRegistBillRealityService = salesReceivesRegistBillRealityService;
	}

	public DetailService getDetailService() {
		return detailService;
	}

	public void setDetailService(DetailService detailService) {
		this.detailService = detailService;
	}

	@Override
	public SalesReceivesRegistBillReality getSalesReceivesRegistBillReality(
			Serializable id) {
		// TODO Auto-generated method stub
		return this.getDao().getSalesReceivesRegistBillReality(id);
	}

}
